import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:get/get.dart';
import 'package:little_painter/sqflite/db_utils.dart';

import 'initialize/init_controller.dart';
import 'initialize/init_routers.dart';

void main() {
  /// getx
  Widget getMaterialApp() {
    return GetMaterialApp(
      initialRoute: InitRouters.initialRoute,
      initialBinding: InitController(),
      getPages: InitRouters.getPages(),
      unknownRoute: InitRouters.unknownRoute,
      navigatorObservers: [FlutterSmartDialog.observer],
      builder: FlutterSmartDialog.init(),
    );
  }

  /// 屏幕适配
  Widget screenUtilInit() {
    return ScreenUtilInit(
      designSize: const Size(375, 812),
      minTextAdapt: true,
      splitScreenMode: true,
      builder: (context, child) => getMaterialApp(),
    );
  }

  WidgetsFlutterBinding.ensureInitialized();

  ///导航栏颜色设置
  const systemUiOverlayStyle = SystemUiOverlayStyle(
    statusBarColor: Colors.transparent,
    statusBarBrightness: Brightness.dark,
    systemNavigationBarColor: Color(0xFF0D171A),
    systemNavigationBarDividerColor: Color(0xFF0D171A),
    systemNavigationBarIconBrightness: Brightness.dark,
    systemNavigationBarContrastEnforced: true,
  );
  SystemChrome.setSystemUIOverlayStyle(systemUiOverlayStyle);

  /// 数据库
  DBUtils.init();

  ///不隐藏状态栏和底部导航栏
  SystemChrome.setEnabledSystemUIMode(
    SystemUiMode.manual,
    overlays: [SystemUiOverlay.top, SystemUiOverlay.bottom],
  );

  runApp(screenUtilInit());
}
